﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Functions;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Response;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
    public class CommentsController : BaseController
    {
        private readonly ICommentsServer _commentsServer;

        public CommentsController(ICommentsServer commentsServer)
        {
            _commentsServer = commentsServer;
        }

        /// <summary>
        /// 获取单个携带回复并且有实际内容的主评论
        /// </summary>
        /// <param name="gid">必须是该商品的评论</param>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.business})]
        public async Task<IActionResult> GetSingleComment(int gid,int id)
        {
            return Send(await _commentsServer.GetSingleCommentAsync(gid,id));
        }

        /// <summary>
        /// 获取热评
        /// </summary>
        /// <param name="gid">必须是该商品的评论</param>
        /// <param name="count">获取热评的数量</param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.business})]
        public async Task<IActionResult> GetHotComments(int gid,int count)
        {
            return Send(await _commentsServer.GetHotCommentsAsync(gid,count));
        }

        /// <summary>
        /// 获取分页
        /// </summary>
        /// <param name="page">第几页</param>
        /// <param name="limit">每页的数据量</param>
        /// <param name="goodId">哪个商品的评论</param>
        /// <param name="firstId">过滤掉的评论</param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.business, CheckLoginRoles.suppliers })]
        public async Task<IActionResult> GetPaginationAsync(int page, int limit, int goodId,int? firstId)
        {
            return Send(await _commentsServer.GetPaginationAsync(page, limit,goodId, firstId));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.business })]
        public async Task<IActionResult> DeleteAsync([FromBody]RequestCommentsDeleteDto dto)
        {
            return Send(await _commentsServer.DeleteAsync(dto));
        }

        /// <summary>
        /// 获取待评论的商品列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="isComment"></param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.business })]
        public async Task<IActionResult> GetCommentPenddingPaginationAsync(int page, int limit, int isComment = 0)
        {
            return Send(await _commentsServer.GetCommentPenddingPaginationAsync(page, limit, isComment,_account.AId, _business.BId));
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.business })]
        public async Task<IActionResult> AddAsync([FromForm]RequestCommentsAddDto dto)
        {
            return Send(await _commentsServer.AddAsync(dto, _account.AId));
        }

        /// <summary>
        /// 获取商品的所有评论数量
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.business })]
        public async Task<IActionResult> GetCommentCount(int gid)
        {
            return Send(await _commentsServer.GetCommentCountAsync(gid));
        }

    }
}
